#include <stdio.h>
#include <assert.h>
#include <winsock2.h>
#include <windows.h>

int main(int argc, char* argv[]) {
	WSADATA wsData;
	SOCKET skt;

	if (0 != WSAStartup(MAKEWORD(2,2), &wsData)) {
		assert(0);
	}

	skt = socket(AF_INET, SOCK_STREAM, 0);
	assert(skt != INVALID_SOCKET);

	{
		struct sockaddr_in addr, addr_other;
		int addr_other_size;

		SOCKET new_skt;

		addr.sin_family = AF_INET;
		addr.sin_port = 0;
		addr.sin_addr.S_un.S_addr = INADDR_ANY;
		if (SOCKET_ERROR == bind(skt, &addr, sizeof(addr))) {
			assert(0);
		}

		if (SOCKET_ERROR == listen(skt, SOMAXCONN)) {
			assert(0);
		}

		addr_other_size = sizeof(struct sockaddr_in);
		new_skt = accept(skt, &addr_other, &addr_other_size);
		if (new_skt == INVALID_SOCKET) {
			assert(0);
		}
		send(new_skt, "hello world", 11, 0);
		getchar();

	}

	WSACleanup();
	return 0;
}
